<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-3-16
 * Time: 下午4:44
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Concerns_model extends MY_Model
{
    protected $table = 'concerns';
    //添加关注 话题
    public function create_long($data) {
        $query = $this->db
            ->select('id')
            ->from('topic')
            ->where('id', $data['tid'])
            ->get();
        if ($this->db->affected_rows()) {
            $re = $query->row_array();
            if($re) {
                $this->db->insert($this->table, $data);
                if ($this->db->affected_rows()) {
                    $id = $this->db->insert_id();
                    $this->db->set('concern', 'concern + 1',false)
                        ->where(array('id' => $data['tid']))
                        ->update('topic');
                    $this->db->affected_rows();
                    return $id;
                }
            }
        }
        return 0;
    }
    public function set($id, $arr) {
        $this->db->set($arr)
            ->where(array('id' => $id))
            ->update($this->table);
        return $this->db->affected_rows();
    }

}